#include "newdomaindialog.h"
#include "ui_newdomaindialog.h"

NewDomainDialog::NewDomainDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::NewDomainDialog){
    ui->setupUi(this);

    connect(ui->buttonBox,&QDialogButtonBox::accepted,this,&NewDomainDialog::onAccept);
}

NewDomainDialog::~NewDomainDialog(){
    delete ui;
}

void NewDomainDialog::onAccept(){
    QString name=ui->textEdit->toPlainText();
    if(DomainNameSystem::isValidDomain(name)){
        DomainNameSystem::DomainInfo info(ui->textEdit->toPlainText(),
                                          ui->textEdit_2->toPlainText(),
                                          ui->textEdit_3->toPlainText(),
                                          ui->textEdit_4->toPlainText());
        DomainNameSystem::DNS().insertDomain(name,info);
        QMessageBox::information(this,tr("Success"),tr("The domain is accept now."));
        accept();
    }
    else{
        QMessageBox::warning(this,tr("Warning"),tr("The domain is not valid. Please try again."));
    }
}
